package com.open.capacity.reimburse.controller;

import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.reimburse.dto.report.BusinesstripBcDto;
import com.open.capacity.reimburse.dto.report.BusinesstripUsageDto;
import com.open.capacity.reimburse.dto.report.TrainingUsageDto;
import com.open.capacity.reimburse.entity.BillBusinesstrip2;
import com.open.capacity.reimburse.service.BillBusinesstrip2Service;
import com.open.capacity.reimburse.service.BillReportService;
import com.open.capacity.utils.DateUtil;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 报销报表
 *
 * @author
 * @email
 * @date 2021-05-11 17:51:27
 */
@RestController
@RequestMapping("billReports")
@Api(tags = "报销报表")
public class BillReportController {

    @Autowired
    private BillReportService reportService;

    /**
     * 差旅费备查表
     */
    @RequestMapping("/businesstripBcb/list")
    public PageResult businesstripBcbList(@RequestParam Map<String, Object> params) {
        PageResult pageResult = reportService.pageBusinesstripBcb(params);
        return pageResult;
    }

    /**
     * 差旅费备查表导出excel
     *
     * @return
     */
    @GetMapping("/businesstripBcb/excel")
    public void businesstripBcbExcel(@RequestParam Map<String, Object> params, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();
        TemplateExportParams paramsExcel = new TemplateExportParams("assets/BusinesstripBcb_templete.xlsx");

        List<BusinesstripBcDto> bill =  reportService.findBusinesstripBcb(params);

        map.put("list", bill);

        modelMap.put(TemplateExcelConstants.FILE_NAME, "差旅费备查表");
        modelMap.put(TemplateExcelConstants.PARAMS, paramsExcel);
        modelMap.put(TemplateExcelConstants.MAP_DATA, map);
        PoiBaseView.render(modelMap, request, response, TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
    }

    /**
     * 差旅费资金使用情况表
     */
    @RequestMapping("/businesstripUsage/list")
    public PageResult businesstripUsageList(@RequestParam Map<String, Object> params) {
        PageResult pageResult = reportService.pageBusinesstripUsage(params);
        return pageResult;
    }

    /**
     * 差旅费资金使用情况表导出excel
     *
     * @return
     */
    @GetMapping("/businesstripUsage/excel")
    public void businesstripUsageExcel(@RequestParam Map<String, Object> params, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();
        TemplateExportParams paramsExcel = new TemplateExportParams("assets/BusinesstripUsage_templete.xlsx");

        List<BusinesstripUsageDto> bill =  reportService.findBusinesstripUsage(params);

        map.put("list", bill);

        modelMap.put(TemplateExcelConstants.FILE_NAME, "差旅费资金使用情况表");
        modelMap.put(TemplateExcelConstants.PARAMS, paramsExcel);
        modelMap.put(TemplateExcelConstants.MAP_DATA, map);
        PoiBaseView.render(modelMap, request, response, TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
    }

    /**
     * 培训费资金使用情况表
     */
    @RequestMapping("/trainingUsage/list")
    public PageResult trainingUsage(@RequestParam Map<String, Object> params) {
        PageResult pageResult = reportService.pageTrainingUsage(params);
        return pageResult;
    }


    /**
     * 培训费资金使用情况表导出excel
     *
     * @return
     */
    @GetMapping("/trainingUsage/excel")
    public void trainingUsageExcel(@RequestParam Map<String, Object> params, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();
        TemplateExportParams paramsExcel = new TemplateExportParams("assets/TrainingUsage_templete.xlsx");

        List<TrainingUsageDto> bill =  reportService.findTrainingUsage(params);

        map.put("list", bill);

        modelMap.put(TemplateExcelConstants.FILE_NAME, "培训费资金使用情况表");
        modelMap.put(TemplateExcelConstants.PARAMS, paramsExcel);
        modelMap.put(TemplateExcelConstants.MAP_DATA, map);
        PoiBaseView.render(modelMap, request, response, TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
    }

}
